function priceCal(){
var psAreaValue = document.getElementById('psArea').value;
var psUnitValue = document.getElementById('psUnitPrice').value;
var psTotalValue = document.getElementById('psTotalPrice').value;


if((psAreaValue!=undefined)&&(psAreaValue!="")&&(psUnitValue!=undefined)&&(psUnitValue!="")
 ){
  document.getElementById('psTotalPrice').value=(psAreaValue*psUnitValue).toFixed(2);
  document.getElementById('psTotalPrice').focus();
  document.getElementById('psPosition').focus();
}

if(((psTotalValue!=null)&&(psTotalValue!="")&&(psTotalValue!=undefined))){
	if(((psAreaValue==undefined)||(psAreaValue=="")||(psAreaValue==null) )
	&& (psUnitValue!=undefined)&&(psUnitValue!="") ){
		document.getElementById('psArea').value=(psTotalValue/psUnitValue).toFixed(2);

	}
	if( ((psUnitValue==undefined)||(psUnitValue=="")||(psUnitValue==null) )
	&&  (psAreaValue!=undefined)&&(psAreaValue!="")){
		document.getElementById('psUnitPrice').value=(psTotalValue/psAreaValue).toFixed(2);
	}
}
}

function priceCalTotal(){
var psAreaValue = document.getElementById('psArea').value;
var psUnitValue = document.getElementById('psUnitPrice').value;
var psTotalValue = document.getElementById('psTotalPrice').value;

if(((psTotalValue!=null)&&(psTotalValue!="")&&(psTotalValue!=undefined))){

	if((psAreaValue!=undefined)&&(psAreaValue!="")){
		document.getElementById('psUnitPrice').value=(psTotalValue/psAreaValue).toFixed(2);
	}
}
}

//create XMLHttpRequest
var http_request;
	function ajax_start()
   {
       var http_request = false;
       if(window.XMLHttpRequest)
	   {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType)
            {
                 http_request.overrideMimeType("text/xml");
            }
       }
       else if (window.ActiveXObject)
       {
             try
			 {
				   http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 }
             catch (e)
			 {
				 try
				 {
					  http_request = new ActiveXObject("Microsoft.XMLHTTP");
				 }
				 catch (e)
		         {}
             }
       }
       if (!http_request)
       {
             window.alert("can not creat HttpRequest object");
             return false;
       }
	   else
	   {
			return http_request;
	   }
   }



//excute ajax Request
   function execute( fun ,style,url,send_style , obj)
   {
        http_request = ajax_start();
		if(!http_request)
		{
			return;
		}
        http_request.onreadystatechange = function(){
			if(http_request.readyState == 4 && http_request.status == 200)
			{
				fun(obj);
			}};

        http_request.open(style, url, true);
        if(send_style=='no')
           http_request.send(null);
        else
            http_request.send(send_style);

   }

//check the car number is duplicated
function isPsNumberReapeat(obj)
{
    var preName=document.getElementById("preName").value;
    if((preName!=null)&&(preName!="")){
    var psNumber=preName+"-"+obj.value;
	URL = encodeURI('parkingSpaceAction.do?method=isPsNumberRepeat&psNumber='+psNumber);
	execute(showMess ,'post' , URL , null , obj);
	}
}

function showMess(obj)
{
   if(http_request.responseText != "")
   {
  		alert(http_request.responseText);
        obj.value = "";
   }
}

function isPsNumberReapeatForEdit(obj)
{
    var psNumber=obj.value;
	var psId = document.getElementById("psId").value;
    if((psNumber!=null)&&(psNumber!="")){
	URL = encodeURI('parkingSpaceAction.do?method=isPsNumberRepeat&psNumber='+psNumber+"&psId="+psId);
	execute(showMessEdit ,'post' , URL , null , obj);
	}
}

function showMessEdit(obj)
{
   if(http_request.responseText != "")
   {
  		alert(http_request.responseText);
   }
}

